//用于创建vuex中的store
import Vuex from 'vuex'
import Vue from 'vue'

Vue.use(Vuex)

const actions = {
    jia(context, value) {
        context.commit('JIA', value)
    },
    jian(context, value) {
        context.commit('JIAN', value)
    },
    incrementOdd(context, value) {
        if (context.state.sum % 2) {
            context.commit('JIA', value)

        }
    },
    incrementWait(context, value) {
        setTimeout(() => {
            context.commit('JIA', value)
        }, 500);
    }
}
const mutations = {
    JIA(state, value) {
        state.sum += value
    },
    JIAN(state, value) {
        state.sum -= value
    },
}
const state = { sum: 0, school: '福州', subject: '前端' }
//类似computed
const getters = {
    tenSumAndOne(state) {
        return state.sum * 10 + 1
    }
}
const store = new Vuex.Store({
    actions,
    mutations,
    state,
    getters,
})
//暴露 导出
export default store

